home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / OOP.SWG / 0054_TV Formatline Unit.pas < prev    next >
Pascal/Delphi Source File  |  1995-02-28  |  23KB  |  838 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       Turbo Pascal Version 6.0                        }
  4. {       Optional FormLine Unit                          }
  5. {       for use with Turbo Vision                       }
  6. {                                                       }
  7. {       Copyright (c) 1991  J. John Sprenger            }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit FormLine;
  12.  
  13. {$O+,F+,S+}
  14.  
  15. interface
  16.  
  17. uses
  18.  
  19.   {Turbo Pascal Run-Time Library Units}
  20.  
  21.   Crt,
  22.  
  23.   {Turbo Vision Standard Units}
  24.  
  25.   Objects, Drivers, Views, Dialogs, App,
  26.  
  27.   {Turbo Vision Accessory Units}
  28.  
  29.   StdDlg, MsgBox;
  30.  
  31. const
  32.  
  33.   { flError, flCharOk and flFormatOK are constants used  }
  34.   { by tFormatLine.CheckPicture.  flError is returned    }
  35.   { when an error is found.  flCharOk when an character  }
  36.   { is found to be appropriate.  And flFormatOk when the }
  37.   { entire input string is found acceptable.             }
  38.  
  39.   flError    = $0000;
  40.   flCharOK   = $0001;
  41.   flFormatOK = $0002;
  42.  
  43.   { flCharError is passed to tFormatLine.ReportError     }
  44.   { when a character does not fit the proper form.       }
  45.   { flFormatError is used when the format is not         }
  46.   { satisfied even though input so far is acceptable.    }
  47.  
  48.   flCharError   = 1;
  49.   flFormatError = 2;
  50.  
  51.   { CommandSet represents the characters used in Format  }
  52.   { Line Pictures.  These match those used by Paradox.   }
  53.  
  54.   CommandSet = ['[','{','?','&','@','!','#','{',',',']',
  55.   '}','*'];
  56.  
  57. type
  58.  
  59.   { tFormatLine }
  60.  
  61.   { tFormatLine is the improved tInputLine object which  }
  62.   { accepts Paradox-form Picture strings to ensure that  }
  63.   { data will be entered in an acceptable form.          }
  64.  
  65.   pFormatLine = ^tFormatLine;
  66.   tFormatLine = object( tInputLine)
  67.     Picture : string;
  68.     constructor Init(var Bounds : tRect; AMaxLen
  69.       : integer; Pic : string);
  70.     function Valid(command : word) : boolean; virtual;
  71.     procedure HandleEvent(var Event : tEvent); virtual;
  72.     function CheckPicture(var s, Pic : string;
  73.       var CPos : integer):word;
  74.     procedure ReportError( kind : word); virtual;
  75.   end;
  76.  
  77.   { tMoneyFormatLine }
  78.  
  79.   { tMoneyFormatLine is an input line intended for use   }
  80.   { real number fields associated with money.  Input is  }
  81.   { preceded with a "$" sign and terminated with a "."   }
  82.   { followed by the appropriate fractional value.        }
  83.  
  84.   pMoneyFormatLine = ^tMoneyFormatLine;
  85.   tMoneyFormatLine = object( tFormatLine )
  86.     constructor Init(var Bounds : tRect; AMaxlen :
  87.       integer);
  88.     procedure SetData(var Rec); virtual;
  89.     procedure GetData(var Rec); virtual;
  90.     function DataSize : word; virtual;
  91.   end;
  92.  
  93.   { tPhoneFormatLine }
  94.  
  95.   { tPhoneFormatLine is for phone number fields. Normal  }
  96.   { 10-digit numbers are entered in the following form   }
  97.   { (###) ###-####.  International numbers are entered   }
  98.   { digit after digit with spaces and hyphens where the  }
  99.   { user deems appropriate.                              }
  100.  
  101.   pPhoneFormatLine = ^tPhoneFormatLine;
  102.   tPhoneFormatLine = object( tFormatLine )
  103.     constructor Init(var Bounds : tRect; AMaxLen :
  104.       integer);
  105.     procedure SetData(var Rec); virtual;
  106.     procedure GetData(var Rec); virtual;
  107.   end;
  108.  
  109.   { tRealFormatLine }
  110.  
  111.   { tRealFormatLine is used for real number fields.  It  }
  112.   { can handle both decimal and scientific notations.    }
  113.  
  114.   pRealFormatLine = ^tRealFormatLine;
  115.   tRealFormatLine = object ( tFormatLine )
  116.     constructor Init(var Bounds : tRect; AMaxLen :
  117.       integer);
  118.     procedure SetData(var Rec); virtual;
  119.     procedure GetData(var Rec); virtual;
  120.     function DataSize : word; virtual;
  121.   end;
  122.  
  123.   { tIntegerFormatLine }
  124.  
  125.   { tIntegerFormatLine is used for integer fields.  It   }
  126.   { accepts signed integers.                             }
  127.  
  128.   pIntegerFormatLine = ^tIntegerFormatLine;
  129.   tIntegerFormatLine = object( tFormatLine )
  130.     constructor Init(var Bounds : tRect; AMaxLen :
  131.       integer);
  132.     procedure SetData(var Rec); virtual;
  133.     procedure GetData(var Rec); virtual;
  134.     function DataSize : word; virtual;
  135.   end;
  136.  
  137.   { tNameFormatLine }
  138.  
  139.   { tNameFormatLine accepts words and capitalizes the    }
  140.   { first character of each word.  This would be used    }
  141.   { proper names and addresses.                          }
  142.  
  143.   pNameFormatLine = ^tNameFormatLine;
  144.   tNameFormatLine = object( tFormatLine )
  145.     constructor Init(var Bounds : tRect; AMaxLen :
  146.       integer);
  147.   end;
  148.  
  149.   { tZipFormatLine }
  150.  
  151.   { tZipFormatLine is used for ZIP and Postal Code       }
  152.   { fields.  It handles U.S. and Canadian format codes.  }
  153.  
  154.   pZipFormatLine = ^tZipFormatLine;
  155.   tZipFormatLine = object( tFormatLine )
  156.     constructor Init(var Bounds : tRect; AMaxLen :
  157.       integer);
  158.     end;
  159.  
  160. implementation
  161.  
  162.  
  163. { Function Copy represents a bit of syntatic sugar for   }
  164. { the benefit of the author.  It changes the Copy func.  }
  165. { so that its parameters represent start and end points  }
  166. { rather than a start point followed by a quantity.      }
  167.  
  168. function Copy(s : string; start, stop : integer) : string;
  169. begin
  170.   if stop < start then Copy:=''
  171.   else Copy:=System.Copy(s,start,stop-start+1);
  172. end;
  173.  
  174.  
  175.  
  176. { Function FindMatch recursively locates the matching   }
  177. { grouping characters for "{" and "[".                  }
  178.  
  179. function FindMatch(P : string) : integer;
  180. var
  181.   i:integer;
  182.   match:boolean;
  183.   c:char;
  184. begin
  185.   i:=2;
  186.   match:=false;
  187.   while (i<=length(P)) and not match do
  188.     begin
  189.       if ((p[i]=']') and (p[1]='[')) or ((p[i]='}') and
  190.         (p[1]='{')) then
  191.         match:=true;
  192.       if p[i]='{' then
  193.         i:=i+FindMatch(Copy(p,i,length(p)))
  194.       else if p[i]='[' then
  195.         i:=i+FindMatch(Copy(p,i,length(P)))
  196.       else inc(i);
  197.     end;
  198.   FindMatch:=i-1;
  199. end;
  200.  
  201.  
  202.  
  203. { tFormatLine.ReportError handles errors found when the  }
  204. { user keys inappropriate characters or presses ENTER    }
  205. { when input is incomplete.                              }
  206.  
  207. procedure tFormatLine.ReportError(kind:word);
  208. var
  209.   w   : word;
  210.   Pic : pstring;
  211. begin
  212.   Pic:=newstr(Picture);
  213.   case kind of
  214.     flCharError :
  215.       begin
  216.         sound(220);
  217.         delay(200);
  218.         nosound;
  219.       end;
  220.     flFormatError :
  221.       begin
  222.         w:=MessageBox('Error in Formatted Input Line'+
  223.           '                      '+
  224.           '%s'+
  225.           '                      '+
  226.           '(Using Paradox Picture Format)',
  227.           @Pic,mfError+mfOkButton);
  228.       end;
  229.     end;
  230.   DisposeStr(Pic);
  231. end;
  232.  
  233.  
  234. { tFormatLine.Valid overrides TView's Valid and reports  }
  235. { any format errors if the user accepts the input string }
  236. { before the entire format requirements have been met.   }
  237.  
  238. function tFormatLine.Valid(command: word):boolean;
  239. var
  240.   result:word;
  241. begin
  242.   result:=CheckPicture(Data^,Picture,CurPos);
  243.   if (result and flFormatOK)=0 then
  244.     begin
  245.       ReportError(flFormatError);
  246.       Select;
  247.       DrawView;
  248.       Valid:=false;
  249.     end
  250.   else Valid:=true;
  251. end;
  252.  
  253.  
  254. { tFormatLine.CheckPicture is the function that inspects }
  255. { the input string passed as S against the Pic string    }
  256. { which holds the Paradox-form Picture.  If an error is  }
  257. { found the position of the error is placed in CPos.     }
  258.  
  259. function tFormatLine.CheckPicture(var s, Pic : string;
  260.   var CPos : integer) : word;
  261. var
  262.   Resolved  : integer;
  263.   TempIndex : integer;
  264.  
  265.  
  266. { Function CP is the heart of tFormatLine.  It           }
  267. { determines if the string, s passed to it fits the      }
  268. { requirements of the picture, Pic.  The number of       }
  269. { characters successful resolved is returned in the      }
  270. { parameter resolved. When groups or repetitions are     }
  271. { encountered CP will call itself recursively.           }
  272.  
  273. function CP(var s : string; Pic : string; var CPos :
  274.   integer; var Resolved : integer) : word;
  275. const
  276.    CharMatchSet = ['#','?','&','@','!'];
  277. var
  278.   i          : integer;
  279.   index      : integer;
  280.   result     : word;
  281.   commit     : boolean;
  282.   Groupcount : integer;
  283.  
  284. { Procedure Succeed resolves defaults and <Space>        }
  285. { default requests                                       }
  286.  
  287.   procedure Succeed;
  288.   var
  289.     t     : integer;
  290.     found : boolean;
  291.   begin
  292.   if (s[i]=' ') and (Pic[index]<>' ') and
  293.     (Pic[index]<>',') then
  294.     begin
  295.       t:=index;
  296.       found:=false;
  297.       while (t<=length(pic)) and not found do
  298.         begin
  299.         if not (Pic[t] in (CharMatchSet+
  300.           ['*','[','{',',',']','}'])) then
  301.           begin
  302.             if pic[t]=';' then inc(t);
  303.             s[i]:=Pic[t];
  304.             found:=true;
  305.           end;
  306.           inc(t);
  307.         end;
  308.     end;
  309.   if (i>length(s)) then
  310.     while not (Pic[index] in
  311.       (CharMatchSet+['*','[','{',',',']','}'])) and
  312.       (index<=length(Pic)) and
  313.       not(Pic[index-1] in ['}',',',']']) do
  314.       begin
  315.         if Pic[index]=';' then inc(index);
  316.         s[i]:=Pic[index];
  317.         if i>length(s) then
  318.           begin
  319.             CPos:=i;
  320.             s[0]:=char(i);
  321.           end;
  322.         inc(i);
  323.         inc(index);
  324.       end;
  325.   end;
  326.  
  327.  
  328. { Function AnyLeft returns true if their are no required }
  329. { characters left in the Picture string.                 }
  330.  
  331.   function AnyLeft : boolean;
  332.   var TempIndex : integer;
  333.   begin
  334.     TempIndex:=index;
  335.     while ((Pic[TempIndex]='[') or (Pic[TempIndex]='*'))
  336.       and (TempIndex<=Length(Pic)) and
  337.       (Pic[TempIndex]<>',') do
  338.       begin
  339.         if Pic[TempIndex]='[' then
  340.           Tempindex:=Tempindex+FindMatch(Copy(Pic,index,
  341.             Length(Pic)))
  342.         else begin
  343.           if not (Pic[TempIndex+1] in ['0'..'9']) then
  344.             begin
  345.               inc(TempIndex);
  346.               if Pic[TempIndex] in ['{','['] then
  347.                 tempIndex:=TempIndex+
  348.                   FindMatch(Copy(pic,index,length(pic)))
  349.               else inc(TempIndex);
  350.             end;
  351.         end;
  352.       end;
  353.     AnyLeft:=(TempIndex<=length(Pic)) and
  354.      (Pic[TempIndex]<>',');
  355.   end;
  356.  
  357.  
  358. { Function CharMatch determines if the current character }
  359. { matches the corresponding character mask in the        }
  360. { Picture string. Alters the character if necessary.     }
  361.  
  362.   function CharMatch : word;
  363.   var result : word;
  364.   begin
  365.     result:=flError;
  366.     case Pic[index] of
  367.       '#': if s[i] in ['0'..'9'] then result:=flCharOk;
  368.       '?': if s[i] in ['A'..'Z','a'..'z'] then
  369.         result:=flCharOk;
  370.       '&': if s[i] in ['A'..'Z','a'..'z'] then
  371.         begin
  372.           result:=flCharOk;
  373.           s[i]:=upcase(s[i]);
  374.         end;
  375.       '@': result:=flCharOk;
  376.       '!':
  377.         begin
  378.          result:=flCharOk;
  379.          s[i]:=upcase(s[i]);
  380.         end;
  381.       end;
  382.     if result<>flError then commit:=true;
  383.     CharMatch:=result;
  384.   end;
  385.  
  386. { Function Literal handles characters which are needed   }
  387. { by the picture by otherwise used as format specifiers. }
  388. { All such characters are preceded by the ';' in the     }
  389. { picture string.                                        }
  390.  
  391.   function Literal : word;
  392.   var result : word;
  393.   begin
  394.     inc(index);
  395.     if s[i]=Pic[index] then result:=flCharOk
  396.     else result:=flError;
  397.     if result<>flError then commit:=true;
  398.     Literal:=result;
  399.   end;
  400.  
  401.  
  402. { Function Group handles required and optional groups    }
  403. { in the picture string.  These are designated by the    }
  404. (* "{","}" and "[","]" character pairs.                 *)
  405.  
  406.   function Group:word;
  407.   var
  408.     result: word;
  409.     TempS: string;
  410.     TempPic: string;
  411.     TempCPos: integer;
  412.     PicEnd: integer;
  413.     TempIndex: integer;
  414.     SwapIndex:integer;
  415.     SwapPic : string;
  416.   begin
  417.     TempPic:=Copy(Pic,index,length(Pic));
  418.     PicEnd:=FindMatch(TempPic);
  419.     TempPic:=Copy(TempPic,2,PicEnd-1);
  420.     TempS:=Copy(s,i,length(s));
  421.     TempCPos:=1;
  422.  
  423.     result:=CP(TempS,TempPic,TempCPos,TempIndex);
  424.  
  425.     if result=flCharOK then inc(GroupCount);
  426.     if (result=flFormatOK) and (groupcount>0) then
  427.       dec(GroupCount);
  428.     if result<>flError then result:=flCharOk;
  429.  
  430.     SwapIndex:=index;
  431.     index:=TempIndex;
  432.     SwapPic:=Pic;
  433.     Pic:=TempPic;
  434.     if not AnyLeft then result:=flCharOk;
  435.     pic:=SwapPic;
  436.     index:=SwapIndex;
  437.  
  438.     if i>1 then s:=copy(s,1,i-1)+TempS else s:=TempS;
  439.  
  440.     CPos:=Cpos+TempCPos-1;
  441.     if Pic[index]='[' then
  442.       begin
  443.       if result<>flError then
  444.          i:=i+TempCPos-1
  445.       else dec(i);
  446.       result:=flCharOK;
  447.       end
  448.     else i:=i+TempCPos-1;
  449.     index:=index+PicEnd-1;
  450.     Group:=result;
  451.   end;
  452.  
  453.  
  454. { Function Repetition handles repeated that may be       }
  455. { repeated in the input string.  The picture string      }
  456. { indicates this possiblity with "*" character.          }
  457.  
  458.   function Repetition:word;
  459.   var
  460.     result:word;
  461.     count:integer;
  462.     TempPic:string;
  463.     TempS:string;
  464.     TempCPos:integer;
  465.     TempIndex:integer;
  466.     SwapIndex:integer;
  467.     SwapPic:string;
  468.     PicEnd:integer;
  469.     commit:boolean;
  470.  
  471.     procedure MakeCount;
  472.     var nstr:string;
  473.         code:integer;
  474.     begin
  475.       if Pic[index] in ['0'..'9'] then
  476.         begin
  477.           nstr:='';
  478.           repeat
  479.             nstr:=nstr+Pic[index];
  480.             inc(index);
  481.           until not(Pic[index] in ['0'..'9']);
  482.           val(nstr,count,code);
  483.         end
  484.       else count:=512;
  485.     end;
  486.  
  487.     procedure MakePic;
  488.     begin
  489.     if Pic[index] in ['{','['] then
  490.       begin
  491.         TempPic:=copy(Pic,index,length(Pic));
  492.         PicEnd:=FindMatch(TempPic);
  493.         TempPic:=Copy(TempPic,2,PicEnd-1);
  494.       end
  495.     else
  496.       begin
  497.         if Pic[index]<>';' then
  498.           begin
  499.             TempPic:=''+Pic[index];
  500.             PicEnd:=3;
  501.             if index=1 then pic:='{'+pic[index]+'}'+
  502.               copy(pic,index+1,length(pic))
  503.             else pic:=copy(pic,1,index-1)+
  504.               '{'+pic[index]+'}'+
  505.               copy(pic,index+1,length(pic));
  506.           end
  507.         else
  508.           begin
  509.             TempPic:=Pic[index]+Pic[index+1];
  510.             PicEnd:=4;
  511.             if index=1 then pic:='{'+pic[index]+
  512.               pic[index+1]+'}'+
  513.               copy(pic,index+1,length(pic))
  514.             else pic:=copy(pic,1,index-1)+'{'+pic[index]+
  515.               pic[index+1]+'}'+copy(pic,index+1,
  516.               length(pic));
  517.           end;
  518.         end;
  519.     end;
  520.  
  521.   begin
  522.     inc(index);
  523.     MakeCount;
  524.     MakePic;
  525.     result:=flCharOk;
  526.     while (count<>0) and (result<>flError) and
  527.       (i<=length(s)) do
  528.       begin
  529.         commit:=false;
  530.         TempS:=Copy(s,i,length(s));
  531.         TempCPos:=1;
  532.  
  533.         result:=CP(TempS,TempPic,TempCPos,TempIndex);
  534.  
  535.         if result=flCharOK then inc(GroupCount);
  536.         if (result=flFormatOK) and
  537.            (groupcount > 0)  then dec(GroupCount);
  538.         if result<>flError then result:=flCharOk;
  539.  
  540.         SwapIndex:=Index;
  541.         Index:=TempIndex;
  542.         SwapPic:=Pic;
  543.         Pic:=TempPic;
  544.         if (not AnyLeft) then result:=flCharOk;
  545.         Pic:=SwapPic;
  546.         index:=SwapIndex;
  547.         if i>1 then s:=copy(s,1,i-1)+TempS else s:=TempS;
  548.         Cpos:=Cpos+TempCpos-1;
  549.         if (count>255) then
  550.            begin
  551.            if result<>flError then
  552.               begin
  553.               i:=i+TempCpos-1;
  554.               if not commit then commit:=true;
  555.               result:=flCharOk;
  556.               end
  557.            else dec(i);
  558.            end
  559.         else i:=i+TempCPos-1;
  560.         inc(i);
  561.         dec(count);
  562.       end;
  563.     dec(i);
  564.     index:=index+PicEnd-1;
  565.     if result=flError then
  566.        if (count>255) and not commit
  567.          then result:=flCharOk;
  568.     repetition:=result;
  569.   end;
  570.  
  571.   begin{ of function CP}
  572.     i:=1;
  573.     index:=1;
  574.     result:=flCharOk;
  575.     commit:=false;
  576.     Groupcount:=0;
  577.     while (i<=length(s)) and (result<>flError) do
  578.       begin
  579.         if index>length(Pic) then result:=flError else
  580.           begin
  581.             if s[i]=' ' then Succeed;
  582.             if Pic[index] in CharMatchSet then
  583.               result:=CharMatch else
  584.             if Pic[index]=';' then
  585.               result:=Literal else
  586.             if (Pic[index]='{') or (Pic[index]='[') then
  587.               result:=Group else
  588.             if Pic[index]='*' then
  589.               result:=Repetition else
  590.             if Pic[index] in [',','}',']'] then
  591.               result:=flError else
  592.             if Pic[index]=s[i] then
  593.               begin
  594.                 result:=flCharOk;
  595.                 commit:=true;
  596.               end
  597.             else result:=flError;
  598.             if (result = flError) and not commit then
  599.               begin
  600.                 TempIndex:=Index;
  601.                 while (TempIndex<=length(Pic)) and
  602.                   ((Pic[TempIndex]<>',') and
  603.                   (Pic[TempIndex-1]<>';'))  do
  604.                   begin
  605.                    if (Pic[TempIndex]='{') or
  606.                      (Pic[TempIndex]=']')
  607.                    then Index:=FindMatch( Copy( Pic,
  608.                      TempIndex,length(Pic)))+TempIndex-1;
  609.                    inc(TempIndex);
  610.                  end;
  611.                if Pic[TempIndex]=',' then
  612.                  begin
  613.                    if Pic[TempIndex-1]<>';' then
  614.                      begin
  615.                        result:=flCharOk;
  616.                        index:=TempIndex;
  617.                        inc(index);
  618.                      end;
  619.                  end;
  620.               end
  621.             else if result<>flError then
  622.               begin
  623.                 inc(i);
  624.                 inc(index);
  625.                 Succeed;
  626.               end;
  627.  
  628.           end;
  629.       end;
  630.     Resolved:=index;
  631.  
  632.     if (result=flCharOk) and
  633.       (GroupCount=0) and
  634.       (not AnyLeft or ((Pic[index-1]=',') and
  635.       (Pic[index-2]<>';')))
  636.     then result:=flFormatOk;
  637.  
  638.     CPos:=i-1;
  639.     CP:=result;
  640.   end;
  641.  
  642. begin{ of function CheckPicture}
  643. Resolved:=1;
  644. CheckPicture:=CP(s,Pic,CPos,Resolved);
  645. end;
  646.  
  647. { tFormatLine.Init simply sets up the inputline and then }
  648. { sets up the Picture string for use by CheckPicture.    }
  649.  
  650. constructor tFormatLine.Init(var Bounds: tRect;
  651.   AMaxLen: integer; Pic : string);
  652. begin
  653.   tInputLine.Init(Bounds,AMaxLen);
  654.   Picture:=Pic;
  655. end;
  656.  
  657. { tFormatLine.HandleEvent intercepts character key       }
  658. { presses and handles inserting these characters into    }
  659. { Data field.  Insertion only occures if a call to       }
  660. { tFormatLine.CheckPicture is successful else            }
  661. { tFormatLine.ReportError is called.  All other events   }
  662. { are passed on to tInputLine.HandleEvent.               }
  663.  
  664. procedure TFormatLine.HandleEvent(var Event: TEvent);
  665. var TempData   : string;
  666.     TempCurPos : integer;
  667.     I          : integer;
  668. begin
  669. if State and sfSelected <> 0 then
  670.    if Event.What=evKeyDown then
  671.       if Event.CharCode in [' '..#255] then
  672.          begin
  673.          TempData:=Data^;
  674.          if State and sfCursorIns<>0 then
  675.             Delete(TempData,CurPos+1,1)
  676.          else begin
  677.               if SelStart<>SelEnd then
  678.                  begin
  679.                  Delete(TempData,SelStart+1
  680.                    ,SelEnd-SelStart);
  681.                  CurPos:=SelStart;
  682.                  end;
  683.               end;
  684.          if Length(TempData)<MaxLen then
  685.             begin
  686.             inc(CurPos);
  687.             insert(Event.CharCode,TempData,CurPos);
  688.             if CheckPicture(TempData,Picture,CurPos)=flError then
  689.                ReportError(flCharError)
  690.             else Data^:=TempData;
  691.             SelStart:=0;
  692.             SelEnd:=0;
  693.             if FirstPos> CurPos then FirstPos:=CurPos;
  694.             I:=CurPos-Size.X+2;
  695.             if FirstPos<I then FirstPos:=I;
  696.             DrawView;
  697.             ClearEvent(Event);
  698.             end;
  699.          end;
  700. tInputLine.HandleEvent(Event);
  701. end;
  702.  
  703.  
  704. constructor tMoneyFormatLine.Init;
  705. begin
  706. tFormatLine.Init(Bounds,AMaxLen,'$#[#][#]*{;,###}.##');
  707. end;
  708.  
  709. procedure tMoneyFormatLine.GetData;
  710. var Figure : real absolute Rec;
  711.     TempData : string;
  712.     i : integer;
  713.     code : integer;
  714. begin
  715.   TempData:=Data^;
  716.   for i:=length(TempData) downto 1 do
  717.       if TempData[i] in ['$',','] then
  718.         Delete(TempData,i,1);
  719.   val(TempData,Figure,code);
  720.   if code<>0 then ReportError(flFormatError);
  721. end;
  722.  
  723. procedure tMoneyFormatLine.SetData;
  724. var Figure : real absolute Rec;
  725.     TempData : string;
  726.     i,decimal, count : integer;
  727. begin
  728.   str(Figure:0:2,TempData);
  729.   i:=pos('.',TempData);
  730.   count:=0;
  731.   while (i<>1) do
  732.     begin
  733.     inc(count);
  734.     dec(i);
  735.     if count=3 then
  736.       begin
  737.       insert(',',TempData,i);
  738.       count:=0;
  739.       end;
  740.     end;
  741.   if TempData[1]=',' then delete(TempData,1,1);
  742.   Data^:='$'+TempData;
  743. end;
  744.  
  745. function tMoneyFormatLine.DataSize : word;
  746. begin
  747. DataSize:=sizeof(real);
  748. end;
  749.  
  750. constructor tPhoneFormatLine.Init;
  751. begin
  752. tFormatLine.Init(Bounds,AMaxLen,
  753.   '(###) ###-####,#*{#, ,-#}');
  754. end;
  755.  
  756. procedure tPhoneFormatLine.GetData;
  757. var i : integer;
  758.     Default : string absolute Rec;
  759. begin
  760.   for i:=length(Data^) downto 1 do
  761.     if Data^[i] in [' ','-','(',')'] then Delete(Data^,i,1);
  762. Default:=Data^;
  763. end;
  764.  
  765. procedure tPhoneFormatLine.SetData;
  766. var i:integer;
  767.     Default : string absolute Rec;
  768. begin
  769. if length(Default)=10 then
  770.   Default:='('+Copy(Default,1,3)+') '+Copy(Default,4,6)+
  771.     '-'+Copy(Default,7,10);
  772. Data^:=Default;
  773. end;
  774.  
  775. constructor tRealFormatLine.Init;
  776. begin
  777. tFormatLine.Init(Bounds, AMaxLen,
  778.   '[+,-]#*#[[.*#][{E,e}[+,-]#[#][#][#]]]');
  779. end;
  780.  
  781. procedure tRealFormatLine.GetData;
  782. var Result : real absolute Rec;
  783.     code : integer;
  784. begin
  785.   val(Data^, Result, code);
  786.   if code<>0 then ReportError(flFormatError);
  787. end;
  788.  
  789. procedure tRealFormatLine.SetData;
  790. var Default : real absolute Rec;
  791. begin
  792.   if Default>1E6 then
  793.     str(Default,Data^)
  794.   else str(Default:0:8,Data^);
  795. end;
  796.  
  797. function tRealFormatLine.DataSize : word;
  798. begin
  799. DataSize:=sizeof(Real);
  800. end;
  801.  
  802. constructor tIntegerFormatLine.Init;
  803. begin
  804. tFormatLine.Init(Bounds,AMaxLen,'[+,-]#*#');
  805. end;
  806.  
  807. procedure tIntegerFormatLine.SetData;
  808. var Default : integer absolute Rec;
  809. begin
  810. str(Default,Data^);
  811. end;
  812.  
  813. procedure tIntegerFormatLine.GetData;
  814. var Result : integer absolute Rec;
  815.     code : integer;
  816. begin
  817. val(Data^,Result,code);
  818. if code<>0 then ReportError(flFormatError);
  819. end;
  820.  
  821. function tIntegerFormatLine.DataSize : word;
  822. begin
  823. DataSize:=sizeof(integer);
  824. end;
  825.  
  826. constructor tNameFormatLine.Init;
  827. begin
  828. tFormatLine.Init(Bounds,AMaxLen,'*[![*?][@][ ]]');
  829. end;
  830.  
  831. constructor tZipFormatLine.Init;
  832. begin
  833. tFormatLine.Init(Bounds,AMaxLen,'#####[-####],&#& #&#');
  834. end;
  835.  
  836. end.
  837.  
  838.